﻿using System;
using System.IO;
using System.Text.RegularExpressions;

namespace _07.ReplaceStartWithEnd
{
    class ReplaceStartWithEnd
    {
        static void Main()
        {
            string text = "";
            using (StreamReader sr = new StreamReader("Text.txt"))
            { 
                char[] c = null;
                while (sr.Peek() >= 0)
                {
                    c = new char[524228];
                    sr.Read(c, 0, c.Length);
                    text += new string(c);
                }
            }

            Console.Write("What you want to replace?\n1. \"start\" with \"end\".\n2. \"end\" with \"start\".\nYour Choise: ");
            switch (Console.ReadLine())
	        {
                case "1":
                    {
                        //text = text.Replace("start", "finish");           //Task7
                        text = Regex.Replace(text, @"\bstart\b", "finish"); //Task8
                        break;
                    }
                case "2":
                    {
                        //text = text.Replace("finish", "start");           //Task7
                        text = Regex.Replace(text, @"\bstart\b", "finish"); //Task8
                        break;
                    }
		        default:
                    {
                        Console.WriteLine("Invalid choise.");
                        Environment.Exit(0);
                        break;
                    }
	        }

            using (StreamWriter sw = new StreamWriter("Text.txt"))
            {
                sw.Write(text);
            }
        }
    }
}
